package com.fckbug.action.upload;

import javax.servlet.http.HttpServletRequest;

import org.apache.commons.validator.ValidatorUtil;
import org.apache.struts.action.ActionError;
import org.apache.struts.action.ActionErrors;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.upload.FormFile;

public class MyForm extends ActionForm {
	/**
	 * 
	 */
	private static final long serialVersionUID = 3037086499441143465L;
	private FormFile myfile;
	public FormFile getMyfile() {
		return myfile;
	}
	public void setMyfile(FormFile myfile) {
		this.myfile = myfile;
	}
    
//    public void reset(ActionMapping mapping, HttpServletRequest request) {
//    	this.file = null;
////        doReset(request);
//    }
    
	/*public ActionErrors validate(ActionMapping mapping,HttpServletRequest request){
		 ActionErrors errors = new ActionErrors();
//		 String userId = WebAppUtil.getLoginedPubUser(request).getId();
//		 String threadId = Constants.getThreadId(userId, getOperate());
//		 String uploadType = request.getParameter("uploadType");
//		 request.setAttribute("uploadType", uploadType);
//		 if(ThreadUtil.isExist(threadId) && !ThreadUtil.isOutOfTime(threadId) && !ThreadUtil.isEnd(threadId)){//存在本用户的正在运行的上传线程
//		     //System.out.println("upload error -1");
//		     errors.add("exist", new ActionError("error.upload.process.exist"));
//		     return errors;
//		 }
//		 if(!WebInit.ableUpload()){//上传线程运行数达到最大数
//		     //System.out.println("upload error 0");
//		     errors.add("maxuploadprocess", new ActionError("error.upload.process.max"));
//		     return errors;
//		 }
		 if(null == file){
		     //System.out.println("upload error 2");
		     errors.add("file", new ActionError("没有找到上传文件"));
		     return errors;
		 }
		 if(file.getFileSize() == 0){
		     //System.out.println("upload error 3");
		     errors.add("file", new ActionError("文件超过100KB"));
		     return errors;
		 }
	     String name = file.getFileName();
		 if(!name.toLowerCase().endsWith(".jpg")){//支持jpg格式
		     //System.out.println("upload error 4");
		     errors.add("file", new ActionError("图片格式错误，支持jpg格式"));
		     return errors;
		 }
		 return null;
	}*/
	
}
